#include "stdafx.h"
#include "logger.h"
#include <stdarg.h>

/*
author: Wu Zhen
email: zhen.wu@gameloft.com
version: 1.0.0
*/

#ifdef WIN32
	#include <windows.h>
#endif

Logger::Logger()
{
}

Logger::~Logger()
{
}
#if defined( WIN32 )
void Logger::setChannelActive(const char* channel, bool enable)
{
	_channelState[channel] = enable;
}

bool Logger::isChannelActive(const char* channel) const
{
	channel_state_map_t::const_iterator it = _channelState.find(channel);
	if (it != _channelState.end()) {
		return it->second;
	} else {
		return false;
	}
}

void Logger::log(const char *cur_file, const char *cur_fun, int cur_line, const char* channel, const char *fmt, ...)
{
//#if defined( WIN32 )
//	if( !::IsDebuggerPresent() )
//	{
//		return ;
//	}
//#endif

	if (!isChannelActive(channel)) {
		return;
	}
	static char content[4096];
	memset(content, 0, sizeof(content));
	int index = sprintf(content, "%s: ", channel);
	va_list ap;
	va_start(ap, fmt);
	vsprintf(content + index, fmt, ap);
	va_end(ap);
#if defined( WIN32	)
	OutputDebugStringA(content);
	OutputDebugStringA("\n");
#endif
}

#endif

